#include <iostream>
#include <iomanip>
#include <sstream>
#include <random>
#include <atomic>

class UUIDHelper
{
public:
    static std::string uuid()
    {
        std::random_device rd;
        std::mt19937_64 mt(rd()); // rd()是机器（硬件）生成的真随机数，mt梅森螺旋算法生成的是伪随机数

        std::uniform_int_distribution<int> distribution(0, 255);
        // 生成8个随机数
        std::stringstream ss;
        for (int i = 0; i < 8; i++)
        {
            ss << std::setw(2) << std::setfill('0') << std::hex << distribution(mt);
            if (i == 3 || i == 5 || i == 7)
                ss << '-';
        }
        static std::atomic<size_t> atomic(1); // 8为OS下，size_t 8字节
        size_t num = atomic.fetch_add(1);     // fetch_add是先获取atomic再自增1
        for (int i = 7; i >= 0; i--)
        {
            ss << std::setw(2) << std::setfill('0') << std::hex << ((num >> 8 * i) & 0xff);
            if (i == 6)
                ss << '-';
        }
        return ss.str();
    }
};

int main()
{
    for (int i = 0; i < 18; i++)
        std::cout << UUIDHelper().uuid() << std::endl;
    return 0;
}